<?php

use IDock\Insurance\ZFIC\Bean\Applicant;
use IDock\Insurance\ZFIC\Bean\ImageInfo;
use IDock\Insurance\ZFIC\Bean\Insured;
use IDock\Insurance\ZFIC\ZFICConstruct;

require_once 'vendor/autoload.php';


$config = [
    'gateway' => 'http://chananel-uat.zhufengic.com:8080',
    'logsDir' => './QomolangmaLogs',
    'timeout' => '60',
    'chalCode' => 'ZFHXY',
    'userCode' => 'ZFHXYTU001',
    'productCode' => 'PRODUCT001',
    'planCode' => 'PLAN001',//燃油车
//    'planCode' => 'PLAN003',//新能源

    'proxy' => '118.123.247.195:45131',
];
//驾意险配置
//$config = [
//    'gateway' => 'http://chananel-uat.zhufengic.com:8080',
//    'logsDir' => './QomolangmaLogs',
//    'timeout' => '60',
//    'chalCode' => 'YD',
//    'userCode' => 'ZFYDJYU014',
//    'productCode' => 'ZFYDJY1121011',
//    'planCode' => 'A',//驾意险方案
//
//    'proxy' => '118.123.247.195:45131',
//];

$IDock = new ZFICConstruct($config);

global $testResponse;

//$testResponse = '';

try {

    if (0) {
        //车型查询接口
        $vehicleName = '小鹏牌NHQ6490BEVGH';
        $searchCode = '';
        $vehiclePriceBegin = '';
        $vehiclePriceEnd = '';
        $vehicleBrand = '';
        $vehicleClass = '';
        $vehicleSeries = '';
        $vehicleMaker = '';
        $modelCode = '';
        $vehicleId = '';
        $pageNo = '1';
        $pageSize = '10';
        $singeinDate = '';//初登日期
        $response = $IDock->CarModelQuery($pageNo, $pageSize, $singeinDate, $vehicleName, $searchCode, $vehiclePriceBegin, $vehiclePriceEnd, $vehicleBrand, $vehicleClass, $vehicleSeries, $vehicleMaker, $modelCode, $vehicleId);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    //询价接口
    if (0) {
        $param = [
            'businessNo' => 'HXY202306121014',//渠道方业务号
            'licenseNo' => '暂未上牌',
            'frameNo' => 'LGBM4AE42HD103297',
            'engineNo' => '803597P',
            'singeinDate' => '2023-07-12',//车辆登记注册日期
            'carOwner' => '樊鑫',
            'carOwnerType' => '1',//车主类型 1:个人 2:团体
            'carOwnerIdentifyType' => '01',//车主证件类型
            'identifyNumber' => '51390219960714105X',//车主证件号码
            'carOwnerPhone' => '18513342227',//车主手机号
            'chgOwnerFlag' => '0',//是否过户
//            'transferDate' => '1999-01-02',//过户日期
            'modelCode' => 'KDAAAI0014',//车型编码
            'platOrderNo' => '',//平台订单号 再次修改订单必传
//            'certificateType' => '01',
//            'certificateNO' => '12344687',
//            'certificateDate' => '2020-02-03',
            'insuredName' => '樊鑫',//被保险人姓名
            'carKindCode' => '100',//车辆(机动车)种类
            'carUseType' => '021000101',//使用性质
            'attachNature' => '01',//所属性质
            'licenseTypeCode' => '02',//号牌种类
            'vehicleCategory' => 'K33',//交管车辆类型
            'licenseColor' => '01',//车牌颜色
            'fuelTypeCode' => 'A',//能源类型
            'seatCount' => '4',//座位数
            'completeKerbMass' => '1.545',//整备质量
            'tonCount' => '',//核定载质量
            'jqStartDate' => '2023-08-05 00:00:00',
            'jqEndDate' => '2024-08-04 23:59:59',
            'syStartDate' => '2023-08-05 00:00:00',
            'syEndDate' => '2024-08-04 23:59:59',
            'groupCode' => '',
            'insuredType' => '1',//投保人类型 1:个人 2:团体
            'appliInsuredName' => '樊鑫',//投保人名称
            'carOwnerGender' => '1',//车主性别
            'carOwnerBirthDate' => '1996-07-14',//车主出生日期
            'appliIdentifyType' => '01',//投保人证件类型
            'appliIdentifyNumber' => '51390219960714105X',//投保人证件号码
            'riskInsuredType' => '1',//被保险人类型 1:个人 2:团体
            'insuredIdentifyType' => '01',//被保险人证件类型
            'insuredIdentifyNumber' => '51390219960714105X',//被保险人证件号码
            'modelEnergyType' => '',//燃料（能源）种类;
            'pureRange' => '',
            'otherEnergyTypeDesc' => '',//其他燃料（能源）种类描述
        ];
        //platOrderNo C20230804170021850000103275
        $response = $IDock->OrderPriceQuery($param);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    //报价接口
    if (0) {
        $kindList = '[
        {
            "kindInd" : "1",
            "kindCode" : "BZ",
            "kindName" : "机动车交通事故责任强制险",
            "amount" : "200000",
            "upperCode" : "0",
            "riskCode" : "0801"
        },
        {
          "kindInd" : "1",
          "kindCode" : "001",
          "kindName" : "车辆损失险",
          "amount" : "548000.00",
          "upperCode" : "0",
          "riskCode" : "0808"
        }]';
        //随车驾意险
        $driAccPlan = [
            'userCode' => 'ZFYDJYU014',
            'productCode' => 'ZFYDJY1121011',
            'planCode' => 'A',
            'uwCountJY' => '1',//份数
        ];

        //优惠系数信息：二次报价时传并可修改系数
        $rate = [
            'platOrderNo' => 'C20230804170021850000103275',
            'riskCode' => '0808',
            'profitType' => 'UNIT',
            'profitName' => 'F03',
            'subProfitName' => '无赔款优待系数',
            'subProfitCode' => '',
            'rate' => '78.9',
            'remark' => '1',
        ];


        $device = [
            'itemNo' => '1',
            'serialNo' => '1',
            'deviceName' => '1111',
            'quantity' => '1',
            'purchasePrice' => '10000',
            'buyDate' => '2021-09-16',
            'actualValue' => '10000',
            'flag' => '',
            'deviceType' => '0070',
            'planCode' => '0000',
            'riskCode' => '0808',
        ];

        //新增源充电桩信息
        $chargingPostData = [
            'chargingPostType' => '',
            'chargingPostCode' => '',
            'chargingPostAddress' => '',
            'chargingPostAddressType' => '',
            'chargingPostKind' => '',
            'chargingPostYearLimit' => '',
            'lossSumLimit' => '',
            'liabilitySumLimit' => '',
            'itemNo' => '',
            'serialNo' => '',
            'kindCode' => '',
        ];

        $param = [
            'platOrderNo' => 'C20230804170021850000103275',
            'businessNo' => 'HXY202306121014',
            'kindList' => json_decode($kindList, true),
            'rateList' => [],
            'jqImmediateFlag' => '0',
            'immediateFlag' => '0',
            'taxRelifFlag' => '02',
            'taxPayerName' => '樊鑫',
            'certiType' => '01',
            'identifyNumber' => '51390219960714105X',
            'taxCompancyCode' => '',
            'taxCompancyName' => '',
            'relifReason' => '',
            'paidFreeCertificate' => '',
            'deductionDueType' => '',
            'freeRate' => '',
            'negotiatedActualValue' => '540000.0',
            'renewalAnswerJQ' => '',
            'renewalAnswerSY' => '',
            'querySequenceNoJQ' => '',
            'querySequenceNoSY' => '',
            'renewalFlag0801' => '',
            'renewalFlag0802' => '',
            'entireExpDiscount' => '',//期望折扣
            'driAccPlan' => $driAccPlan,//随车驾意方案
            'deviceList' => [],
//            'chargingPostList' => [$chargingPostData],
            'businessLevel' => 'A',//四川地区必传 传值：A、B、C、D
            'taxDocumentDate' => '',
            'taxPaidAreaCode' => '',
        ];

        $response = $IDock->OfferOrderPrice($param);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    //下单核保接口
    if (0) {
        $businessNo = 'HXY202306121014';
        $platOrderNo = 'C20230804170021850000103275';
        $appliInfo = new Applicant();
        $appliInfo->setAppliName('樊鑫');//投保人名称
        $appliInfo->setIdentifyType('01');//证件类型
        $appliInfo->setIdentifyNumber('51390219960714105X');//证件号码
        $appliInfo->setsex('1');//性别
        $appliInfo->setbirthDate('1996-07-14');//出生日期
        $appliInfo->setmobileNumber('17071625466');//手机号码
        $appliInfo->setapplicantType('1');//投保人类型
        $appliInfo->setworkUnit('');//
        $appliInfo->setaddress('成都市');//联系地址
        $appliInfo->setpostCode('300260');//邮政编码
        $appliInfo->setofficePhone('');//单位电话
        $appliInfo->setcontactName('');//联系人
        $appliInfo->setcontactMobile('');//联系人电话
        $appliInfo->setemail('baoxian23265987@163.com');
        $appliInfo->setidcardInstitutions('成都市市公安局');//签发机构  采集人为投保人且证件类型为身份证时不可为空
        $appliInfo->setnationality('汉');//民族
        $appliInfo->setidentifyStartDate('2016-10-31');//身份证有效期起期
        $appliInfo->setidentifyEndDate('2036-10-31');//身份证有效期止期
        $appliInfo->setidentifyNature('1');//投保人类别 1:身份证
        $appliInfo->setcontactIdentifyType('');//联系人证件类型
        $appliInfo->setcontactIdentifyNumber('130223197110090075');//联系人证件号码
        $appliInfo->setcontactSex('');//联系人性别
        $appliInfo->setitemProvinceCode('510000');//省份代码
        $appliInfo->setitemCityCode('510100');//城市代码
        $appliInfo->setitemProvinceCName('四川省');//省份名称
        $appliInfo->setitemCityCName('成都市');//城市名称


        $insuredInfo = new Insured();
        $insuredInfo->setinsuredName('樊鑫');
        $insuredInfo->setidentifyType('01');
        $insuredInfo->setidentifyNumber('51390219960714105X');
        $insuredInfo->setsex('1');
        $insuredInfo->setbirthDate('1996-07-14');
        $insuredInfo->setmobileNumber('17071625466');
        $insuredInfo->setinsuredType('1');
        $insuredInfo->setinsuredAddress('天津市');
        $insuredInfo->setpostCode('300260');
        $insuredInfo->setofficePhone('');
        $insuredInfo->setcontactName('');
        $insuredInfo->setcontactMobile('');
        $insuredInfo->setcarInsuredRelation('1');
        $insuredInfo->setemail('baoxian23265987@163.com');
        $insuredInfo->setidcardInstitutions('北京市公安局');
        $insuredInfo->setnationality('汉');
        $insuredInfo->setidentifyStartDate('2016-10-31');
        $insuredInfo->setidentifyEndDate('2036-10-31');
        $insuredInfo->setinsuredNature('1');

        //特别约定信息列表
        $coClauseList = [
//            [
//                'platOrderNo' => 'C20230804170021850000103275',
//                'chalOrderNo' => 'werfc13ww1222xsbg',
//                'lineNo' => '1',
//                'serialNo' => '1',
//                'clauseCode' => 'T001_1',
//                'clauseName' => '交强险投保提示',
//                'context' => '为更好地保障您的权益,请您在发生保险事故后保留出险第一现场,并立即致电24小时服务电话:10108848',
//                'riskCode' => '0801'
//            ],
        ];
        //核保意见
        $salesmanAdvice = '';

        //驾意险必填
        $uwCountJY = '1';
        $quantityJY = '1';
        $startDateJY = '2023-08-05';
        $endDateJY = '2024-08-05';
        $chalCode = 'YD';
        $userCode = 'ZFYDJYU014';
        $productCode = 'ZFYDJY1121011';
        $planCode = 'A';
        $response = $IDock->InsuranceConfirm($businessNo, $platOrderNo, $appliInfo, $insuredInfo, $coClauseList, $salesmanAdvice, $uwCountJY, $quantityJY, $startDateJY, $endDateJY, $chalCode, $userCode, $productCode, $planCode);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //获取身份验证码
        $platOrderNo = 'C20230804170021850000103275';//平台订单号
        $response = $IDock->GetVerifyCode($platOrderNo);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (1) {
        //获取支付url
        $platOrderNo = 'C20230804170021850000103275';
        $issUserCode = 'ABCDFE';
        $response = $IDock->GetPaymentUrl($platOrderNo, $issUserCode);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //投保单状态查询接口
        $platOrderNo = 'C20230804170021850000103275';
        $response = $IDock->OrderStatusQuery($platOrderNo);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    //影像上传接口
    if (0) {
        $platOrderNo = 'C20230804170021850000103275';
        $imageInfo = new ImageInfo();
        $fileData = base64_encode(file_get_contents('./front.jpg'));
        $imageInfo->setFileSize(filesize('./front.jpg'));
        $imageInfo->setFileDate(date('Y-m-d H:i:s'));
        $imageInfo->setFileData($fileData);
        $imageInfo->setFileName('1236589547877.jpg');
        $imageInfo->setFileExt('.jpg');
        $imageInfo->setFileType('P');
        $imageInfo->setSerialNo('1');
        $imageInfo->setTypeName1('投保业务');
        $imageInfo->settypeName2('新车');
        $imageInfo->setTypeName3('已完税/减免税凭证');
        $imageInfo->setTypePath1('01');
        $imageInfo->setTypePath2('05');
        $imageInfo->setTypePath3('08');

        $imageInfoVMList = [$imageInfo];
        $response = $IDock->UploadFile($platOrderNo, $imageInfoVMList);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //投保单回撤接口
        $platOrderNo = 'C20180725141910885000104229';
        $proposalNo = 'M354010136320180000058';
        $riskCode = '0000';
        $commitTime = '2018-07-25';
        $recallType = '00';

        $response = $IDock->OrderCancel($platOrderNo, $proposalNo, $riskCode, $commitTime, $recallType);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //验车码获取接口
        $businessNo = 'daklghrwlhg43215431';
        $queryDate = '2018-07-29';

        $response = $IDock->GetCarVerifyCode($businessNo, $queryDate);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //获取交易流水号
        $businessNo = '789275fd340275935290';//渠道方业务号
        $proposalNo = 'M233000136320180000305';//投保单号
        $response = $IDock->GetOrderNo($businessNo, $proposalNo);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //交易流水号撤销接口
        $tradeNo = '23784682364726493';
        $proposalNo = 'M233000136320180000305';
        $attrube1 = '1';
        $attrube2 = '2';
        $operateCode = '';
        $response = $IDock->CancelOrderNo($tradeNo, $proposalNo, $attrube1, $attrube2, $operateCode);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //订单撤销接口
        $insuredNo = 'C20180816094558144000205193';
        $userId = '';
        $response = $IDock->RevokeOrderNo($insuredNo, $userId);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }


} catch (Exception $e) {
    var_dump($e->getMessage());
}


